from wxpyview.ui.component.common.basewidget import *

class StatusBar(Widget):
    def _getParentParam(self, meta_widget):
        stopping_point = ['Frame']       
        return ComponentLibrary.findFirstMatchedAncestor(meta_widget, stopping_point)
    
    def _setParams(self, meta_widget):
        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
        
        self.fields = int(dom.getAttribute("fields"))
        self.sizes = map(lambda x: abs(int(x)), dom.getAttribute("sizes").split(','))
        self.width_type = dom.getAttribute("width")
        
        if self.width_type == "relative":
            self.sizes = map(lambda x: -x, self.sizes)
        
    def create(self, meta_widget):
        self._setParams(meta_widget)

        parent = self._getParentParam(meta_widget)
        statusbar = parent.CreateStatusBar()
        statusbar.SetFieldsCount(self.fields)
        statusbar.SetStatusWidths(self.sizes)
        
        return statusbar